/* 
 * Copyright (c) 2010 Adam Markiewicz
 * 
 * Permission is hereby granted, free of charge, to any person
 * obtaining a copy of this software and associated documentation
 * files (the "Software"), to deal in the Software without
 * restriction, including without limitation the rights to use,
 * copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the
 * Software is furnished to do so, subject to the following
 * conditions:
 * 
 * The above copyright notice and this permission notice shall be
 * included in all copies or substantial portions of the Software.
 * 
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
 * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
 * OTHER DEALINGS IN THE SOFTWARE.
 */

/**
 * @file core/memory/newallocator.h
 * @author Adam Markiewicz
 */

#ifndef __CLEA_CORE_MEMORY_NEWALLOCATOR
#define __CLEA_CORE_MEMORY_NEWALLOCATOR

#include <core/types.h>

namespace Clea
{
    namespace Core
    {
        namespace Memory
        {
            /**
             * @brief Global new allocator
             * 
             * Allocates memory using global new operator.
             * 
             * @ingroup allocators
             */
            class NewAllocator
            {
                public:
                    /**
                     * @brief Allocates memory
                     * 
                     * @param n Number of bytes
                     */
                    inline static void* allocate(size_type n) {
                        return ::operator new(n);
                    }
                    
                    /**
                     * @brief Allocates aligned memory
                     * 
                     * Allocates memory with a specified alignment. Currently not
                     * supported.
                     * 
                     * @todo Support aligned allocation
                     * 
                     * @param n Number of bytes
                     * @param alignment Alignment
                     */
                    inline static void* allocateAligned(size_type n, size_type alignment);
                    
                    /**
                     * @brief Frees memory
                     * 
                     * @param ptr Memory pointer
                     * @param n Size of memory
                     */
                    inline static void deallocate(void* ptr, size_type n) {
                        ::operator delete(ptr);
                    }
                    
                    /**
                     * @brief Resizes previously allocated block
                     * 
                     * Not supported. Always returns false.
                     * 
                     * @param ptr Memory pointer
                     * @param nOld Size of previous allocation
                     * @param nNew New size
                     */
                    inline static bool resize(const void* ptr, size_type nOld, size_type nNew) {
                        return false;
                    }
            };
        }
    }
}

#endif // __CLEA_CORE_MEMORY_NEWALLOCATOR
